<!DOCTYPE html>
<html>
<?php //var_dump($output);exit;?>
<head>
    <meta charset="utf-8">
    <title>金贵银业</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <!--标准mui.css-->
    <link rel="stylesheet" href="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/css/mui.min.css">
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/css/app.css" />
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/css/zhaojinyin_index.css" />
    <link href="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <script src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/js/mui.min.js"></script>
    <script type="text/javascript" charset="utf-8">
        mui.init({
            swipeBack: true //启用右滑关闭功能
        });

    </script>
    <style>
        .title {
            margin: 20px 15px 10px;
            color: #6d6d72;
            font-size: 15px;
        }

        .div_lable label {
            width: 30%;
            padding: 0 20px;
        }
    </style>
</head>

<body style="padding-bottom: 150px;">

<div class="mui-bar" style="height: 45px; ">

    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>

    <!--
        时间：2016-03-24
        描述：右边按钮
         mui-bar-nav
    -->

    <h1 class="mui-title" style="">购物车（<?php echo $output['cart_count'];?>）</h1>
</div>

<div class="mui-content mui-row mui-fullscreen mt45">
    <div style="margin-bottom: 15px;">
        <?php foreach($output['cart_list'] as $c){  ?>
            <div class="mui-input-row mui-checkbox mui-left" style="background:#FFFFFF;color:#333333;" >
                <label style="line-height: 25px; width: 100%; padding-left: 35px;"><img src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/03.png" style="width: 20px; vertical-align: middle; margin-right: 10px;"><?php echo $c['store_name'];?>></label>

                <div style="position: relative; margin-top: -35px; left: 65%; height: 30px;display: none;">
                    <span style="padding: 0 12px;">编辑</span><span style="color: #EEEEEE;">|</span><span style="padding: 0 12px;" >删除</span>
                </div>

            </div>

            <div class="mui-input-row mui-checkbox mui-left" style="background: #F7F7F7;padding:10px 2px 0px 0px;">
                <input style="margin-top: 35px; margin-left: -16px;" name="checkbox" value="<?php echo $c['cart_id'];?>" type="checkbox" class="sel" checked="checked">
                <div style="padding-left: 36px;width: 40%; float: left;">
                    <a href="/mobile/index.php?act=goods&op=goods_body&goods_id=<?php echo $c['goods_id'];?>"><img src="/data/upload/shop/store/goods/<?php echo $c['store_id'];?>/<?php echo $c['goods_image'];?>" style="width: 70%;border: 1px solid #EEEEEE;"></a>
                </div>

                <div style="float: right;width: 60%;" class="cart-litemw-cnt" cart_id="<?php echo $c['cart_id'];?>">

                    <div style="float: left;height: 40px; border-bottom: 1px solid #FFFFFF; text-align: center; padding:0 10px; width: 70%;">
                        <img src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/-1.png" style="vertical-align: middle;float: left;" class="minus-wp" />
                        <input value="<?php echo $c['goods_num'];?>" style="width: 40px; height: 25px; line-height: 25px; text-align: center; padding: 0 !important; border: 0;background: none;" type="text" class="buy-num" name="num" />
                        <img src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/--2.png" style="vertical-align: middle; float: right;" class="add-wp" />
                        <div style="margin-bottom: 10px;" class="clear"></div>
                        <label style="color: #666;padding: 0; text-align: left;"><span style="width: 50%;white-space: nowrap;text-overflow: ellipsis; overflow: hidden;"><?php echo $c['goods_name'];?></span>
                            <br/>单价:￥<?php echo $c['goods_price'];?></label>
                    </div>
                    <div style="float: left; width: 30%;">
                        <button style="border: 0; background: #ab9154; height: 110px;width:100%;border-radius: 0px; float: right;color: #FFFFFF;margin-top: -15px;" class="cart-list-del" cart_id="<?php echo $c['cart_id'];?>">删除</button>
                    </div>

                </div>
            </div>

        <?php $order_count+=($c['goods_price']*$c['goods_num']);}?>


    </div>



    <div style=" height: 120px;width: 100%;"></div>
</div>

<div style="position: fixed; background: #FFFFFF; width: 100%; height:55px; z-index: 100; bottom: 51px;">
    <div class="mui-input-row mui-checkbox mui-left">
        <label style="padding-left: 45px;line-height: 32px;width: 28%;">全选</label>
        <input style="margin-left: -10px;margin-top: 6px;" name="selectAll" id="selectAll" value="1" type="checkbox" checked="checked" >
        <div style="float: right; width: 72%;line-height: 56px;">
            <span>合计:</span><span class="color_red total_price1">￥<?php echo $order_count;?></span>
            <span>不含运费</span>
            <button id="jiesuan" style="border: 0; background: #ab9154; height: 55px;border-radius: 0px; float: right;color: #FFFFFF;" class="goto-settlement">结算<?php if(count($output['cart_list'])>0){?>(<?php echo count($output['cart_list']);?>)<?php }?></button>

        </div>
    </div>
</div>

<nav class="mui-bar mui-bar-tab">
    <a id="indexz" class="mui-tab-item1 mui-active" href="/mobile">
        <span class="mui-icon"><img style="width: 20px;" src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/1_0111.png"></span>
        <span class="mui-tab-label">首页</span>
    </a>

    <a id="tabbar-with-fenlei" class="mui-tab-item1" href="/mobile/index.php?act=goods_class">
        <span class="mui-icon "><img style="width: 20px;" src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/1_0121.png"></span>
        <span class="mui-tab-label">分类</span>
    </a>

    <a id="gouwuche" class="mui-tab-item1" href="/mobile/index.php?act=shopcart">
        <span class="mui-icon "><img style="width: 20px;" src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/1_0132.png"><span class="mui-badge" style="<?php if(!$output['cart_count']){echo 'display: none;';}?>"><?php echo $output['cart_count'];?></span></span>
        <span class="mui-tab-label cAB9154">购物车</span>
    </a>

    <a id="tabbar-me-contact" class="mui-tab-item1" href="/mobile/index.php?act=member_index&op=member_index">
        <span class="mui-icon"><img style="width: 20px;" src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/images/1_0141.png"></span>
        <span class="mui-tab-label">我</span>
    </a>
</nav>
<script src="<?php echo MOBILE_RESOURCE_SITE_URL; ?>/js/jquery.js"></script>
<script language="JavaScript">

    var SiteUrl = "http://<?php echo $_SERVER['HTTP_HOST'];?>";
    var ApiUrl = "http://<?php echo $_SERVER['HTTP_HOST'];?>/mobile/";
    var pagesize = 10;
    var WapSiteUrl = "http://<?php echo $_SERVER['HTTP_HOST'];?>/mobile/";


    function getcookie(name){
        var strcookie=document.cookie;
        var arrcookie=strcookie.split("; ");
        for(var i=0;i<arrcookie.length;i++){
            var arr=arrcookie[i].split("=");
            if(arr[0]==name)return arr[1];
        }
        return "";
    }

    var member_id = "<?php echo $_SESSION['member_id'];?>";
    var key = getcookie('key');
    if(member_id==''){
        window.location.href = WapSiteUrl+'index.php?act=login';
    }

    //删除购物车
    function delCartList(){
        var  cart_id = $(this).attr("cart_id");
        $.ajax({
            url:ApiUrl+"/index.php?act=member_cart&op=cart_del",
            type:"post",
            data:{key:key,cart_id:cart_id},
            dataType:"json",
            success:function (res){
               if(!res.datas.error && res.datas == "1"){
                   window.location.reload();
               }else{
                   alert(res.datas.error);
               }
            }
        });
    }
    //购买数量减
    function minusBuyNum(){
        var self = this;
        editQuantity(self,"minus");
    }
    //购买数量加
    function addBuyNum(){
        var self = this;
        editQuantity(self,"add");
    }
    //购买数量增或减，请求获取新的价格
    function editQuantity(self,type){
        var sPrents = $(self).parents(".cart-litemw-cnt");
        var cart_id = sPrents.attr("cart_id");
        var numInput = sPrents.find(".buy-num");
        var buynum = parseInt(numInput.val());
        var quantity = 1;
        if(type == "add"){
            quantity = parseInt(buynum+1);
            //
        }else {
            if(buynum >1){
                quantity = parseInt(buynum-1);
            }else {
                alert('购买数目必须大于1');
                return;
            }
        }
        $.ajax({
            url:ApiUrl+"/index.php?act=member_cart&op=cart_edit_quantity",
            type:"post",
            data:{key:key,cart_id:cart_id,quantity:quantity},
            dataType:"json",
            success:function (res){
                    if(!res.datas.error){
                        numInput.val(quantity);
                        sPrents.find(".goods-total-price").html(res.datas.total_price);
                        var goodsTotal = $(".goods-total-price");
                        var totalPrice = parseFloat("0.00");
                        for(var i = 0;i<goodsTotal.length;i++){
                            totalPrice += parseFloat($(goodsTotal[i]).html());
                        }
                        $(".total_price").html("￥"+totalPrice.toFixed(2));
//                        alert(res.datas.total_price);
                    }else{
                        alert(res.datas.error);
                    }
            }
        });
    }

    //去结算
    function goSettlement(){
        //购物车ID
        var cartIdArr = [];
        var cartIdEl = $(".cart-litemw-cnt");
        for(var i = 0;i<cartIdEl.length;i++){
            var cartId = $(cartIdEl[i]).attr("cart_id");
            var cartNum = parseInt($(cartIdEl[i]).find(".buy-num").val());
            var cartIdNum = cartId+"|"+cartNum;
            cartIdArr.push(cartIdNum);
        }
        var cart_id = cartIdArr.toString();
        window.location.href = WapSiteUrl + "index.php?act=shopbuy&op=buy_step1&ifcart=1&cart_id="+cart_id;
    }

    $(".cart-list-del").click(delCartList);
    //购买数量，减
    $(".minus-wp").click(minusBuyNum);
    //购买数量加
    $(".add-wp").click(addBuyNum);

    $("#selectAll").click(function(){
        checkIt = $("#selectAll").is(":checked");
        $(".sel").attr("checked",checkIt);
    });

    $(".goto-settlement").click(goSettlement);
    //已选订单总数
    function countNum() {
        var m = 0;
        var checkbox = document.getElementsByName("checkbox"); // id表示你的checkbox的name属性
        for (var i = 0; i < checkbox.length; i++) {
            if (checkbox[i].checked == true) {
                m = m + 1;
            }
        }
        return m;
    }
    //订单总价
    function countBill() {

    }
    $(".sel,#selectAll").bind('change',function(){
//        alert(countNum());
        $("#jiesuan").html('结算('+countNum()+')');
    });

</script>
</body>

</html>